package com.qty.apkviewer.sp

import android.content.Context
import android.content.SharedPreferences

/**
 * SharedPreferences 帮助类
 */
class SharedPreferencesHelper private constructor(context: Context) {

    private val mSharedPreference: SharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE)

    /**
     * 应用是否是第一次启动
     *
     * @return 应用如果是第一次启动返回 true，否则返回 false
     */
    fun isFirstUse(): Boolean {
        return mSharedPreference.getBoolean(KEY_FIRST_USE, true)
    }

    /**
     * 设置应用不是第一次启动
     */
    fun setNotFirstUse() {
        mSharedPreference.edit().putBoolean(KEY_FIRST_USE, false).apply()
    }

    /**
     * 单例
     */
    companion object {

        private var mInstance: SharedPreferencesHelper? = null

        private const val SHARED_PREFERENCES_NAME = "ApkViews"
        private const val KEY_FIRST_USE = "key_first_use"
        fun getInstance(context: Context): SharedPreferencesHelper {
            if (mInstance == null) {
                mInstance = SharedPreferencesHelper(context)
            }
            return mInstance!!
        }
    }
}